package com.zzxz.practicaltrainingsys.repository;


import com.zzxz.practicaltrainingsys.entity.ChatMessage;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long> {

    @Query("SELECT c FROM ChatMessage c WHERE c.sessionId = :sessionId ORDER BY c.createTime DESC")
    List<ChatMessage> findBySessionIdOrderByCreateTimeDesc(@Param("sessionId") String sessionId, Pageable pageable);

    @Query("SELECT c FROM ChatMessage c WHERE c.sessionId = :sessionId ORDER BY c.createTime ASC")
    List<ChatMessage> findBySessionIdOrderByCreateTimeAsc(@Param("sessionId") String sessionId);
}